{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd \n",
    "import numpy as np \n",
    "from itertools import product"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "countries = ['us','de','dk','fr','it','nl','se','sp']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>value</th>\n",
       "      <th>free</th>\n",
       "      <th>se</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>sigma</th>\n",
       "      <td>2.053009</td>\n",
       "      <td>True</td>\n",
       "      <td>0.084701</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>beta</th>\n",
       "      <td>0.970000</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>phi</th>\n",
       "      <td>0.323550</td>\n",
       "      <td>True</td>\n",
       "      <td>0.038703</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>psi</th>\n",
       "      <td>0.179346</td>\n",
       "      <td>True</td>\n",
       "      <td>0.041753</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>delta_h1</th>\n",
       "      <td>-0.978317</td>\n",
       "      <td>True</td>\n",
       "      <td>0.390853</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>delta_h2</th>\n",
       "      <td>3.447890</td>\n",
       "      <td>True</td>\n",
       "      <td>0.048774</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>eta</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>tfp</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>price</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>risk</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             value   free        se\n",
       "name                               \n",
       "sigma     2.053009   True  0.084701\n",
       "beta      0.970000  False       NaN\n",
       "phi       0.323550   True  0.038703\n",
       "psi       0.179346   True  0.041753\n",
       "delta_h1 -0.978317   True  0.390853\n",
       "delta_h2  3.447890   True  0.048774\n",
       "eta       0.000000  False       NaN\n",
       "tfp       1.000000  False       NaN\n",
       "price     1.000000  False       NaN\n",
       "risk      0.000000  False       NaN"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test = pd.read_pickle('output/params_wage_us.pkl')\n",
    "test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "pars_select = ['delta_h1','delta_h2','price','tfp']\n",
    "stat = ['par','se']\n",
    "tuples = list(product(*[pars_select,stat]))\n",
    "table = pd.DataFrame(index=pd.MultiIndex.from_tuples(tuples),columns=countries)\n",
    "for c in countries: \n",
    "\tdf = pd.read_pickle('output/params_wage_'+c+'.pkl')\n",
    "\tfor p in pars_select:\n",
    "\t\ttable.loc[(p,'par'),c] = df.loc[p,'value']\n",
    "\t\ttable.loc[(p,'se'),c] = df.loc[p,'se']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "pars_select = ['delta_h1','delta_h2','price','tfp']\n",
    "labels = ['$\\\\alpha_{10}$','$\\\\alpha_{11}$','$\\\\frac{p}{p_{US}}$','$\\\\frac{A}{A_{US}}$']\n",
    "maps_labels = dict(zip(pars_select,labels))\n",
    "table.index = pd.MultiIndex.from_tuples(list(product(*[labels,['','se']])))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "for c in table.columns:\n",
    "\ttable[c] = table[c].astype('float64')\n",
    "\ttable[c] = table[c].round(3)\n",
    "\ttable[c] = table[c].astype('str')\n",
    "\ttable[c] = np.where(table[c]=='nan','-',table[c])\n",
    "\tfor s in table.index:\n",
    "\t\tif s[1]=='se':\n",
    "\t\t\tif table.loc[s,c]!='-':\n",
    "\t\t\t\tfmt = \"({se})\"\n",
    "\t\t\t\ttable.loc[s,c] = fmt.format(se=table.loc[s,c])\n",
    "table.index = pd.MultiIndex.from_tuples(list(product(*[labels,['','']])))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>us</th>\n",
       "      <th>de</th>\n",
       "      <th>dk</th>\n",
       "      <th>fr</th>\n",
       "      <th>it</th>\n",
       "      <th>nl</th>\n",
       "      <th>se</th>\n",
       "      <th>sp</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">$\\alpha_{10}$</th>\n",
       "      <th></th>\n",
       "      <td>-0.978</td>\n",
       "      <td>-1.266</td>\n",
       "      <td>-1.574</td>\n",
       "      <td>-1.228</td>\n",
       "      <td>-0.833</td>\n",
       "      <td>-1.411</td>\n",
       "      <td>-1.367</td>\n",
       "      <td>0.202</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <td>(0.391)</td>\n",
       "      <td>(0.046)</td>\n",
       "      <td>(0.038)</td>\n",
       "      <td>(0.124)</td>\n",
       "      <td>(0.048)</td>\n",
       "      <td>(0.056)</td>\n",
       "      <td>(0.047)</td>\n",
       "      <td>(0.04)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">$\\alpha_{11}$</th>\n",
       "      <th></th>\n",
       "      <td>3.448</td>\n",
       "      <td>4.051</td>\n",
       "      <td>4.274</td>\n",
       "      <td>3.795</td>\n",
       "      <td>3.823</td>\n",
       "      <td>3.941</td>\n",
       "      <td>4.306</td>\n",
       "      <td>3.548</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <td>(0.049)</td>\n",
       "      <td>(0.201)</td>\n",
       "      <td>(0.029)</td>\n",
       "      <td>(0.064)</td>\n",
       "      <td>(0.02)</td>\n",
       "      <td>(0.031)</td>\n",
       "      <td>(0.039)</td>\n",
       "      <td>(0.061)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">$\\frac{p}{p_{US}}$</th>\n",
       "      <th></th>\n",
       "      <td>1.0</td>\n",
       "      <td>0.98</td>\n",
       "      <td>1.002</td>\n",
       "      <td>0.717</td>\n",
       "      <td>0.689</td>\n",
       "      <td>0.84</td>\n",
       "      <td>1.025</td>\n",
       "      <td>1.134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <td>-</td>\n",
       "      <td>(0.241)</td>\n",
       "      <td>(0.029)</td>\n",
       "      <td>(0.026)</td>\n",
       "      <td>(0.039)</td>\n",
       "      <td>(0.082)</td>\n",
       "      <td>(0.017)</td>\n",
       "      <td>(0.111)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">$\\frac{A}{A_{US}}$</th>\n",
       "      <th></th>\n",
       "      <td>1.0</td>\n",
       "      <td>0.987</td>\n",
       "      <td>1.225</td>\n",
       "      <td>0.92</td>\n",
       "      <td>0.614</td>\n",
       "      <td>1.003</td>\n",
       "      <td>0.779</td>\n",
       "      <td>0.805</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <td>-</td>\n",
       "      <td>(0.313)</td>\n",
       "      <td>(0.037)</td>\n",
       "      <td>(0.295)</td>\n",
       "      <td>(0.059)</td>\n",
       "      <td>(0.1)</td>\n",
       "      <td>(0.037)</td>\n",
       "      <td>(0.04)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                          us       de       dk       fr       it       nl  \\\n",
       "$\\alpha_{10}$         -0.978   -1.266   -1.574   -1.228   -0.833   -1.411   \n",
       "                     (0.391)  (0.046)  (0.038)  (0.124)  (0.048)  (0.056)   \n",
       "$\\alpha_{11}$          3.448    4.051    4.274    3.795    3.823    3.941   \n",
       "                     (0.049)  (0.201)  (0.029)  (0.064)   (0.02)  (0.031)   \n",
       "$\\frac{p}{p_{US}}$       1.0     0.98    1.002    0.717    0.689     0.84   \n",
       "                           -  (0.241)  (0.029)  (0.026)  (0.039)  (0.082)   \n",
       "$\\frac{A}{A_{US}}$       1.0    0.987    1.225     0.92    0.614    1.003   \n",
       "                           -  (0.313)  (0.037)  (0.295)  (0.059)    (0.1)   \n",
       "\n",
       "                          se       sp  \n",
       "$\\alpha_{10}$         -1.367    0.202  \n",
       "                     (0.047)   (0.04)  \n",
       "$\\alpha_{11}$          4.306    3.548  \n",
       "                     (0.039)  (0.061)  \n",
       "$\\frac{p}{p_{US}}$     1.025    1.134  \n",
       "                     (0.017)  (0.111)  \n",
       "$\\frac{A}{A_{US}}$     0.779    0.805  \n",
       "                     (0.037)   (0.04)  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "table.to_latex('../tables/table_e2_country_specific_estimates.tex')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Average US-EU differences\n",
    "\n",
    "This number is used in counterfactual analysis. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9124285714285715"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table.index = pd.MultiIndex.from_tuples(list(product(*[labels,['p','se']])))\n",
    "prices = table.loc[('$\\\\frac{p}{p_{US}}$','p'),:]\n",
    "prices['de':].astype('float64').mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9047142857142856"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "table.index = pd.MultiIndex.from_tuples(list(product(*[labels,['p','se']])))\n",
    "prices = table.loc[('$\\\\frac{A}{A_{US}}$','p'),:]\n",
    "prices['de':].astype('float64').mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "cf2a50979671a58939829e6829efb726aa5da11149213b77bd50351f899d04fb"
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
